import Vue from 'vue'
import VueRouter from 'vue-router'

/* import Home from '../pages/home/home.vue'
import Search from '../pages/search/search.vue'
import Order from '../pages/order/order.vue'
import Personal from '../pages/personal/personal.vue'
import Login from '../pages/login/login.vue' */
// 路由组件的懒加载
const Home  = () => import('../pages/home/home.vue')
const Search = () => import('../pages/search/search.vue')
const Order = () => import('../pages/order/order.vue')
const Personal = () => import('../pages/personal/personal.vue')
const Login = () => import('../pages/login/login.vue')


import Shop from '../pages/shop/shop.vue'
import ShopGoods from '../pages/shop/shop-goods/shop-goods.vue'
import ShopComment from '../pages/shop/shop-comments/shop-comments.vue'
import ShopOwner from '../pages/shop/shop-owner/shop-owner.vue'
// 下面这个几个是同一个需求的不同实现方案
/* import ShopGoodTest from '../pages/shop/shop-goods/shop-goods-betterScroll.vue'
import ShopGoodAnchor from '../pages/shop/shop-goods/anchor_point.vue'
import ShopGoodAnchorBe from '../pages/shop/shop-goods/anchor_point_better.vue' */
import ShopGoodsGetoffsetTop from '../pages/shop/shop-goods/getOffsetTop.vue'
const NotFound = ()=>import('../pages//notfound/notfound.vue')
Vue.use(VueRouter)
//解决相同路由跳转的error
//原型
const originPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originPush.call(this,location).catch(err=> err)
}
const router = new VueRouter({
  routes: [
    {
      path: '/home',
      component: Home,
      meta: {
        requireFooter:true
      }
    },
    {
      path: '/search',
      component: Search,
      meta: {
        requireFooter:true
      }
    },
    {
      path: '/order',
      component: Order,
      meta: {
        requireFooter:true
      }
    },
    {
      path: '/personal',
      component: Personal,
      meta: {
        requireFooter:true
      }
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/shop',
      component: Shop,
      children: [
        {
          path: '/shop/shopgoods',
          component: ShopGoods
        },
        {
          path: '/shop/shopcomment',
          component: ShopGoodsGetoffsetTop
        },
        {
          path: '/shop/shopowner',
          component: ShopOwner
        },
        {
          path: '/shop',
          redirect: '/shop/shopgoods'
        }
      ]
    },

    //防止用户弄错路由路径
    {
      path: '*',
      component: NotFound,
    },
  ]
})

export default router
